import 'package:get/route_manager.dart';
import 'package:share_fit/app/controllers/device/device_view.dart';
import 'package:share_fit/app/controllers/home/home_view.dart';
import 'package:share_fit/app/controllers/main/launch_view.dart';
import 'package:share_fit/app/controllers/main/main_binding.dart';
import 'package:share_fit/app/controllers/main/main_view.dart';
import 'package:share_fit/app/controllers/space/space_view.dart';
import 'package:share_fit/app/controllers/sports/sports_view.dart';
import 'package:share_fit/app/routes/device_routes.dart';
import 'package:share_fit/app/routes/login_routes.dart';
import 'package:share_fit/app/routes/navigation_history_observer.dart';
import 'package:share_fit/app/routes/space_routes.dart';
import 'package:share_fit/app/routes/sports_routes.dart';

import 'home_routes.dart';

class Routes {
  static const launchPage = '/launch';
  static const mainPage = '/main';
  static const homePage = '/home';
  static const sportsPage = '/sports';
  static const devicePage = '/device';
  static const spacePage = '/space';
  static const INITIAL = '/launch';
  static NavigationHistoryObserver navigationHistoryObserver = NavigationHistoryObserver();

  static List<GetPage> getPages() {
    List<GetPage> pages = [];

    pages.addAll(routes);
    pages.addAll(DeviceRoutes.getPages());
    pages.addAll(HomeRoutes.getPages());
    pages.addAll(SpaceRoutes.getPages());
    pages.addAll(LoginRoutes.getPages());
    pages.addAll(SportsRoutes.getPages());

    return pages;
  }

  static final routes = [
    GetPage(
      name: launchPage,
      page: () => LaunchPage(),
    ),
    GetPage(
      name: mainPage,
      page: () => MainPage(),
      binding: MainBinding(),
    ),
    GetPage(
      name: homePage,
      page: () => HomePage(),
    ),
    GetPage(
      name: sportsPage,
      page: () => SportsPage(),
    ),
    GetPage(
      name: devicePage,
      page: () => DevicePage(),
    ),
    GetPage(
      name: spacePage,
      page: () => SpacePage(),
    ),
  ];

  static bool isPageOpened(name) {
    bool res = false;
    final routes = navigationHistoryObserver.history;
    for (var route in routes) {
      if (route.settings.name == name) {
        res = true;
        break;
      }
    }
    // return routes.any((route) => route.settings is T);

    return res;
  }
}